package com.dragon.modules.yuegou.enums.code;

import com.dragon.common.constant.enums.IBusinessCode;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 秒杀状态码
 * 
 * @author 李基方
 *
 */
public enum SeckillCode implements IBusinessCode {

	SECKILL_NO_START(22001, "秒杀尚未开始"),
	
	SECKILL_END(22002, "秒杀已结束，记得下次早点来喔"),
	
	SECKILL_COMPLETE(22003, "该商品已经被抢完啦"),
	
	SECKILL_UNLINE(22004, "该商品秒杀活动已下线"),
	
	SECKILL_MAX_BUY_NUM(22005, "已达限购次数，无法购买"),
	
	SECKILL_DAY_FORMAT_FAIL(22006, "日期参数错误，参数示例：2019-08-01"),
	
	SECKILL_SPU_NOT_NULL(22007, "秒杀商品信息不能为空"),
	
	SECKILL_VIEW_TIME(22008, "展示时间不能晚于活动时间"),
	
	USE_BEGIN_TIME_CANNOT_BE_GREATER_THAN_BEGIN_DATE(22009,"核销时间不能早于活动开始时间!"),
	
	USE_END_TIME_CANNOT_BE_GREATER_THAN_END_DATE(22010,"核销时间不能晚于活动结束时间!"),
	
	SECKILL_START_TIME(22099, "秒杀活动时间不能小于当前时间");
	
	
	private final Integer code;

	private final String message;

	private SeckillCode(Integer code, String message) {
		this.code = code;
		this.message = message;
	}

	public Integer getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}

	/**
	 * 把code转化为ResponseCode枚举
	 * 
	 * @param code 代码
	 * @return
	 */
	public static SeckillCode from(Integer code) {
		if (code == null) {
			return null;
		}
		return CODE_MAP.get(code);
	}

	/**
	 * Code Map for ResponseCode
	 */
	private static final Map<Integer, SeckillCode> CODE_MAP = Stream.of(SeckillCode.values())
			.collect(Collectors.toMap(SeckillCode::getCode, e -> e));
	
}
